home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / bin / gui / win32 / src / wrapit.cpp < prev    next >
C/C++ Source or Header  |  1997-02-26  |  6KB  |  229 lines

  1. /***************************************************************************
  2. *
  3. *  Filename:  Doperl.cpp
  4. *
  5. *  Main routine to execute perl scripts using registry information.
  6. *
  7. *  Date  :   11/20/1995
  8. *  Changed By Marc Sacoolas 
  9. ****************************************************************************/
  10.  
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <process.h>
  16. #include <errno.h>
  17.  
  18.  
  19.  
  20. void ErrorLog(int errno)
  21. {
  22.     switch (errno) 
  23.     {
  24.         case 1:
  25.             printf("change directory failed \n");
  26.             break;    
  27.             
  28.         default:    
  29.            printf("Content-type: text/html\n\n");
  30.            printf("<p><p><p><h2>The search portion of this software is not properly installed. Please re-install the software.</h2>\n");
  31. //           printf("ErrorCode: %d\n", errno);
  32.         break;
  33.     }
  34. }
  35.  
  36. void main(int argc, char **argv)
  37. {
  38.     unsigned int ichar;
  39.     int idest =1;
  40.     int line =0;
  41.     char in_string[81];
  42.     char Command[_MAX_PATH];
  43.     char *in_ptr = in_string;
  44.     FILE *input_file;
  45.  
  46.     if ( (input_file = fopen(argv[1], "r")) == NULL )
  47.     { 
  48.         printf("Could not open file %s", argv[1]);
  49.         exit(0);
  50.     }
  51.     while (fgets(in_string,80, input_file) != NULL )
  52.     {
  53.       line++;
  54.       in_ptr = in_string;
  55.  
  56.       if (in_ptr = strstr(in_ptr, "#windows:"))
  57.       { 
  58.           /*
  59.          for (ichar = 0; ichar < (strlen(in_ptr)-10); ichar++, idest++) {
  60.          
  61.          Command[ichar] = in_ptr[ichar +9];
  62.  
  63.          }
  64.          */
  65.         
  66.           // Added 02/28/97 ---START----
  67.           strcpy(Command, &(in_ptr[strlen("#windows:")]));
  68.           char *cp = strrchr(Command, '\n');
  69.           if(cp)
  70.               *cp = '\0';
  71.  
  72.           // Added 02/28/97 ----END----
  73.  
  74.        //Command[ichar] = '\0';
  75.        break;              
  76.       }
  77.       
  78.       // printf("here:'%s'",Command);
  79.      
  80.     }
  81.           /* no windows: found in top 20 */
  82.       if (line > 5) 
  83.       {
  84.         /*
  85.            printf("Content-type: text/html\n\n");
  86.         printf("<p><p><p><h2>This is for Solaris only.</h2>\n");
  87.         exit(0);
  88.         */
  89.  
  90.         printf("\n\n\n\n\n\n");
  91.         printf("This is for Solaris only. \n");
  92.         printf("\n");
  93.         printf ("Press <ENTER> to continue. \n");
  94.         fflush(stdout);
  95.  
  96.         char emptyBuff[80];
  97.  
  98.         fgets(emptyBuff, 80, stdin);
  99.  
  100.       }
  101.     //printf("idest =%d, ichar = %d\nnewstring =%s<\n",idest,ichar,Command);
  102.  
  103.     char *getQuery(char *s);
  104.     /*  open appropriate registry keys  */
  105.  
  106. //#if 0    
  107.     HKEY  softKey,archKey, discKey,volKey;
  108.     LONG  errVal;
  109.     /* open software hive using LOCAL_MACHINE */
  110.     if ((errVal=RegOpenKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)"Software",0,KEY_ALL_ACCESS,
  111.                      &softKey)) != ERROR_SUCCESS) {
  112.         ErrorLog(2);
  113.         printf("Unable to open the hive HKEY_CURRENT_USER\\Software\n");
  114.         printf("ErrorCode: %d\n", errVal);
  115.  
  116.     }
  117.     /* SunSoft Dir */
  118.     if ((errVal=RegOpenKeyEx(softKey,(LPCTSTR)"SunSoft",0,KEY_ALL_ACCESS,
  119.                      &archKey)) != ERROR_SUCCESS) {
  120.         ErrorLog(3);
  121.         printf("Unable to open the hive SunSoft");    
  122.         printf("ErrorCode: %d\n", errVal);
  123.  
  124.     }
  125.     /* discKey Dir */
  126.     if ((errVal=RegOpenKeyEx(archKey,(LPCTSTR)"Sun Solutions CD",0,KEY_ALL_ACCESS,
  127.                      &discKey)) != ERROR_SUCCESS) {
  128.         ErrorLog(3);
  129.         printf("Unable to open the hive discKey");    
  130.         printf("ErrorCode: %d\n", errVal);
  131.  
  132.     }
  133.     /* get specific volume of CD */ 
  134.     if ((errVal=RegOpenKeyEx(discKey,(LPCTSTR)"April 1997",0,KEY_ALL_ACCESS,
  135.                      &volKey)) != ERROR_SUCCESS) {
  136.         ErrorLog(3);
  137.         printf("Unable to open the hive April 1997\n");    
  138.         printf("ErrorCode: %d\n", errVal);
  139.  
  140.     }
  141.  
  142.     /* get values from hive. 
  143.      * get the PATH */
  144.     char PATH[_MAX_PATH],PRODDIR[_MAX_PATH];
  145.     
  146.     DWORD  dwLen = _MAX_PATH;
  147.     
  148.     if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"PATH",0,NULL,
  149.                         (unsigned char *)PATH,&dwLen)) != ERROR_SUCCESS) {
  150.         ErrorLog(6);
  151. printf("Unable to open PATH\n");        
  152.         printf("ErrorCode: %d\n", errVal);
  153.  
  154.     }
  155.  
  156.     /* get the PRODDIR */
  157.         dwLen = _MAX_PATH;
  158.  
  159.     if ((errVal=RegQueryValueEx(volKey,(LPTSTR)"PRODDIR",0,NULL,
  160.                         (unsigned char *)PRODDIR,&dwLen)) != ERROR_SUCCESS) {
  161.         ErrorLog(7);
  162.     printf("Unable to open PRODDIR\n");
  163.     printf("ErrorCode: %d\n", errVal);
  164.  
  165.     }
  166.  
  167.     
  168. //#endif
  169.  
  170.   // execute httpd -- jeeves
  171.  
  172.   //char *Query = convertQuery(getenv("QUERY_STRING"));
  173.   SetEnvironmentVariable((LPCTSTR)"PATH",(LPCTSTR)PATH);
  174.  
  175.  
  176.   /*printf ("%s\n%s\n%s\n%s\n%s\n%s\n",PATH,CLASSPATH,JAVA_EXE,JAVAHOME,PRODDIR,NETSCAPEHOME);*/
  177.  
  178.   char *Cmd = new char[strlen(PRODDIR)+strlen(Command)+25];
  179.  
  180.   sprintf(Cmd,"%s\\%s",PRODDIR,Command);
  181.   
  182.  
  183.    printf("\n\nSTARTINg...'%s'\n",Cmd);
  184.     STARTUPINFO  StartInfo;
  185.     PROCESS_INFORMATION ProcessInfo;
  186.     
  187.     ZeroMemory((void *)&StartInfo, sizeof(STARTUPINFO));
  188.     ZeroMemory((void *)&ProcessInfo, sizeof(PROCESS_INFORMATION));
  189.  
  190.     StartInfo.cb = sizeof(STARTUPINFO);
  191.     StartInfo.lpDesktop = "";
  192.     StartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
  193.     //StartInfo.hStdOutput = (HANDLE CreateFile();
  194.     StartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  195.     StartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
  196.     StartInfo.dwFlags = STARTF_USESTDHANDLES;
  197.     
  198.     //  if (!CreateProcess(NULL,(LPTSTR)Cmd,NULL,NULL,TRUE,0,NULL,NULL,&StartInfo,&ProcessInfo)) 
  199.      if (!CreateProcess((LPTSTR) Cmd,(LPTSTR)NULL,NULL,NULL,TRUE,0,NULL,NULL,&StartInfo,&ProcessInfo)) 
  200.     {
  201.         printf("create process Failed: %d \n", GetLastError());
  202.         // delete[] Cmd;
  203.     }
  204.     char *end_proc = (char *) malloc(5);
  205.     char *end_thrd = (char *) malloc(5);
  206.  
  207.     WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
  208.     CloseHandle(ProcessInfo.hProcess);
  209.     CloseHandle(ProcessInfo.hThread);
  210.     delete[] Cmd;
  211.  
  212.     //GetExitCodeProcess(ProcessInfo.hProcess,(LPDWORD)end_proc);
  213.     //GetExitCodeThread(ProcessInfo.hThread,(LPDWORD)end_thrd);
  214.     //printf("Exit code proc = %s, thread = %s.\n", end_proc, end_thrd);
  215.  
  216.     
  217.  
  218.  
  219.     //TerminateProcess (ProcessInfo.hProcess,0);
  220.     //TerminateThread (ProcessInfo.hThread,0);
  221.     //GenerateConsoleCtrlEvent(CTRL_C_EVENT,ProcessInfo.dwProcessId);
  222.  
  223. }
  224.  
  225.     
  226.     
  227.                  
  228.                  
  229.